package com.bluesky.plum.uimodels.render.html.components;

import com.bluesky.javawebbrowser.domain.html.HtmlPage;
import com.bluesky.javawebbrowser.domain.html.tags.form.input.Button;

public class HButton extends
		com.bluesky.plum.uimodels.standard.components.Button {

	com.bluesky.javawebbrowser.domain.html.tags.form.input.Button btn;

	public HButton() {

		// btn.setAttribute("onclick", "_oum_post()");
	}

	@Override
	public void initialize() {
		super.initialize();

		if (template != null && template.length() > 0) {
			HtmlPage page = new HtmlPage(template);
			btn = (Button) page.getRoot().getById(
					componentType.toString());
		} else {
			btn = new com.bluesky.javawebbrowser.domain.html.tags.form.input.Button();

		}

		// textbox.setValue((String) getField().value);
	}

	@Override
	public Object getNativeComponent() {
		// HTML Tag's name is UIComponent's ID
		btn.setName(getId());

		btn.setValue(getCaption());

		if (getClickListener() != null) {
			btn.setOnClick(String.format("_oum_post(this,'click')", getId()));
		}

		return btn;
	}

}
